package tree.test404;

import listbyorder.utils.TreeNode;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/18 8:48
 */
public class Solution2 {

    // 使用递归， 用标志位做判断
    public int sumOfLeftLeaves(TreeNode root) {
        if (root == null) return 0;
        return dfs(root, false);
    }

    private int dfs(TreeNode root, boolean f) {
        if (root == null) return 0;

        if (f && root.left == null && root.right == null) return root.val;

        return dfs(root.left, true) + dfs(root.right, false);
    }
}
